package com.tanhua.server.controller;

import com.tanhua.domain.db.UserInfo;
import com.tanhua.domain.vo.SettingsVo;
import com.tanhua.server.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

@RestController
@RequestMapping("/users")
@Slf4j
public class UserInfoController {

    @Autowired
    private UserService userService;

    @GetMapping
    //根据用户id【token查询】查询详细信息
    public ResponseEntity<Object> findUserInfo(Long userID, Long huanxinID) throws InvocationTargetException, IllegalAccessException {
        log.info("接口名称：用户资料-读取");
        return userService.findUserInfoById(userID, huanxinID);
    }

    @PutMapping
    //修改用户详细信息
    public ResponseEntity<Object> updateUserInfo(@RequestHeader("Authorization") String token, @RequestBody UserInfo userInfo) {
        return userService.updateUserInfo(token, userInfo);
    }

    @PostMapping("/header")
    //修改用户头像
    public ResponseEntity<Object> updateUserHeader(@RequestHeader("Authorization") String token, @RequestBody MultipartFile headPhoto) throws IOException {
        return userService.updateUserHead(headPhoto, token);
    }

    @GetMapping("/counts")
    //互相喜欢、粉丝-统计
    public ResponseEntity<Object> counts() {
        return userService.counts();
    }

    @GetMapping("/friends/{type}")
    //互相喜欢、喜欢、粉丝、谁看过我 - 翻页列表
    public ResponseEntity<Object> getTypeQuery(@PathVariable Integer type,
                                               @RequestParam(defaultValue = "1") Integer page,
                                               @RequestParam(defaultValue = "10") Integer pagesize,
                                               String nickname) throws InvocationTargetException, IllegalAccessException {
        return userService.getTypeQuery(type, page, pagesize, nickname);
    }

    @PostMapping("/fans/{uid}")
    //粉丝 - 喜欢
    public ResponseEntity<Object> commitLove(@PathVariable("uid") Integer uid) {
        return userService.commitLove(uid);
    }

    @DeleteMapping("/like/{uid}")
    //喜欢 - 取消
    public ResponseEntity<Object> deleteLike(@PathVariable("uid") Integer uid){
        return userService.deleteLike(uid);
    }
}
